home *** CD-ROM | disk | FTP | other *** search
- /*
- #-------------------------------------------------------------------------------------------
- #
- # Program: < DMZ 1.1 >
- # File: < dmzAT.c >
- #
- # by Pete Helme
- # of <Apple Macintosh Developer Technical Support - or wheverever>
- # modified by Rich Kubota
- # 3/25/92 rrk Fixed program so that if no zones are selected and the "no zones (*)"
- # item selected, the local zone is searched.
- # 3/25/92 rrk Implemented J. Luther's socket listener, replacing Pete's listener
- # 3/25/92 rrk Updated code to work with Think C 5.0.
- #
- # Copyright © 1990 Apple Computer, Inc.
- # All rights reserved.
- #
- #-------------------------------------------------------------------------------------------
- */
-
- /*
- * dmz Sample AppleTalk Stuff
- *
- * This unit handles all AppleTalk functions for dmz. Including: AppleTalk
- * presence verification and activation, socket opening, set self send enabling
- * name binding protocol registration, bridge presence verification,
- * zone name lookups, hot dish zapper, name removal, socket closing & no weeds.
- *
- */
-
- #ifndef THINK_C
- #include <types.h>
- #include <quickdraw.h>
- #include <toolutils.h>
- #include <fonts.h>
- #include <events.h>
- #include <windows.h>
- #include <dialogs.h>
- #include <menus.h>
- #include <desk.h>
- #include <textedit.h>
- #include <scrap.h>
- #include <segload.h>
- #include <osevents.h>
- #include <files.h>
- #include <devices.h>
- #include <memory.h>
- #include <appletalk.h>
- #include <lists.h>
- #include <SysEqu.h>
- #include <Script.h>
- #include <Packages.h>
- #include <OSUtils.h>
- #include <CursorCtl.h>
- #endif
-
- #include "dmz.h"
-
- /*
- * Socket listener routines found in dmz.a.o
- */
- extern pascal OSErr SL_INITSKTLISTENER(QHdrPtr freeQ, QHdrPtr usedQ);
- extern void SL_THELISTENER();
-
- void doGetZoneListPhs2();
-
- /* globals from afar */
- /* out main dialog */
- extern DialogPtr gLookupDialog;
- extern DialogPtr gMyDialog;
- extern char gNameGlob[34];
- extern SysEnvRec GMAC; /* set up by Initialize */
-
- /* and others */
- Ptr gBuffPtr;
- myMPPParamBlock *gPBLkUP;
- Boolean gUpdateListFlag;
- Boolean gLookupFinished;
- NamesTableEntry gMyNTE;
- AddrBlock gTheBridgeAddress;
- Boolean gHasPhase2 = false;
- NamesTableEntry gLookupNTE;
-
- Ptr GTHEVBLPTR;
- Ptr GTHETASKPTR;
-
- /*
- * Inline routines for saving & restoring A5 in our PLookupName completion routine.
- *
- * move.l a5, -(a7)
- * move.l $FFFC(a0), a5 ; -4(A0)
- *
- */
- pascal void saveThatA5()
- = {0x2f0d, 0x2a68, 0xFFFC};
-
- /*
- * move.l (a7)+, a5
- */
- pascal void restoreThatA5()
- = {0x2a5f};
-
- /*
- * Boring Pascal string concat routine. Skip ahead a bit.
- */
- char *Pstrcat(char *s, char *t)
- {
- long i, length;
- char *p;
-
- length = *t;
- p = s + *s + 1;
- t++;
-
- for(i=0;i<length;i++)
- *p++ = *t++;
-
- *s += length;
- return s;
- }
-
- /*
- * Returns length of pascal type strings. Again, quite boring.
- */
- unsigned char PStrLen(char *e)
- {
- unsigned char length;
-
- length = *e;
- return(length);
- }
-
- /*
- * Returns true if two Pascal strings are the same, false otherwise.
- */
-
- Boolean PStrComp(char *str1, char *str2)
-
- {
- unsigned char i;
- unsigned char j;
- Boolean ok;
-
- if (*str1 != *str2)
- return(false); /* strings are of unequal length */
-
- i = *str1;
- ok = true; /* assume strings are the same */
- j = 0;
- for (j = 0; j < i; j++) {
- if (*(++str1) != *(++str2))
- return(false);
- }
- return(true);
- }
-
- /*
- * Removes a specific NBP Lookup from queue if one pending. Why? So we don't hurt ourselves.
- *
- */
- void killLookups()
- {
- MPPParamBlock killPB;
- OSErr resultCode;
-
- if(gPBLkUP->myMPP.MPPioResult == 1) {
- killPB.NBPnKillQEl = (Ptr)&gPBLkUP->myMPP.MPP.qLink;
- resultCode = PKillNBP(&killPB, false);
- }
- }
-
- /*
- * Removes our name and ATP socket.
- */
- void removeMyNameAndSocket()
- {
- MPPParamBlock pb;
- OSErr resultCode;
-
- /*
- * pointer to entityName
- */
- pb.NBPentityPtr = (Ptr)&gMyNTE.nt.entityData[0];
- resultCode = PRemoveName(&pb, false);
-
- }
-
- /*
- * Shutdown our AppleTalk usage. Disposes of name lookup buffers.
- * Calls to remove our NBP name.
- */
- void closeUpOurAppleTalk()
- {
- killLookups();
-
- if(gBuffPtr != 0L)
- DisposPtr(gBuffPtr);
- if(gPBLkUP != 0L)
- DisposPtr((Ptr) gPBLkUP);
- removeMyNameAndSocket();
- }
-
- /*
- * Registers name from the System's STR -16096 resource. (what is usually seen in the Chooser)
- */
-
- void registerMyName()
- {
- MPPParamBlock pb;
- OSErr resultCode;
- long byteCount;
- StringHandle userName;
-
- byteCount = 0L;
-
- /* this grabs the name from the user's Chooser name string. If there is nothing
- there we'll substitute our own name */
- userName = GetString(kMachineNameResourceID);
- if(**userName == 0)
- BlockMove("\pYour name here.", *userName, 15L);
-
- NBPSetNTE((Ptr)&gMyNTE, *userName, "\pnot anything", "\p*", gMyNTE.nt.nteAddress.aSocket);
-
- pb.NBPinterval = 2;
- pb.NBPcount = 3;
-
- /* wants pointer to NamesTableEntry NOT entityName! */
- pb.NBP.NBPPtrs.ntQElPtr = (Ptr)&gMyNTE;
- pb.NBPverifyFlag = 1; /* verify that we be the only one! */
-
- resultCode = PRegisterName(&pb, false);
- }
-
-
- /*
- * Enables AppleTalk option to talk to one's own node. ONLY for SE's, //'s or MacPluses with AppleTalk driver of v48 or greater!!
- */
- void enableSetSelfSend()
- {
-
- SetSelfparms pb;
- OSErr resultCode;
-
- pb.newSelfFlag = true; /* set self send option */
- resultCode = PSetSelfSend((MPPPBPtr) &pb, false);
- if(resultCode!=noErr)
- SysBeep(1);
- }
-
-
- /*
- * Checks to see if we are running AppleTalk Phase 2 compatible drivers.
- */
- void phase2Check()
- {
- if(GMAC.atDrvrVersNum >= 53)
- gHasPhase2 = true;
- else
- HideDItem(gLookupDialog, kPhase2Item);
- }
-
-
- /*
- * Opens up AppleTalk. Opens our ATP socket.
- */
- void InitAppleTalkVars()
- {
- extern void getTheZoneList();
-
- /*
- * buffer necessary for async name lookups
- */
- gPBLkUP = (myMPPParamBlock *) NewPtr(sizeof(myMPPParamBlock));
- gBuffPtr = NewPtr(30000L);
-
- if(gPBLkUP != 0L) {
- if(ATPLoad() == noErr) {
- phase2Check();
- getTheZoneList();
- enableSetSelfSend() ;
- registerMyName();
- }
- else
- ExitToShell();
- }
- }
-
-
-
- /*
- * in order for us to use the standard qsort() algorithm, our data must be alligned in
- * an orderly fashion with a set offset from each data entry. This routine takes care of
- * that through simple _BlockMove manipulations.
- */
- void addToUnpackedBuffer(Ptr oldBuffer, Ptr newBuffer, short numGot, short total)
- {
- long oldIndex = 0L, newIndex = 0L;
- short i;
-
- for(i=0;i<numGot;i++) {
- BlockMove((Ptr)oldBuffer+oldIndex, (Ptr)newBuffer+(newIndex+total)*33, 33L);
- oldIndex += (char)((Ptr)oldBuffer+oldIndex)[0]+1L;
- newIndex += 1;
- }
- }
-
-
- /*
- * return our local zone name the old fasioned way
- */
- void getMyZone(char *myZoneBuffer)
- {
- BDSElement myZoneBDS;
- ATPParamBlock ZonePB;
-
- myZoneBDS.buffSize = 33;
- myZoneBDS.buffPtr = (Ptr) myZoneBuffer;
- myZoneBDS.dataSize = 0;
- myZoneBDS.userBytes = 0;
-
- ZonePB.ATPatpFlags = 0;
- ZonePB.ATPioCompletion = 0L;
- ZonePB.ATPuserData = 0; /* ATP user data */
- ZonePB.ATPaddrBlock = gTheBridgeAddress;
- ZonePB.ATPreqLength = 0;
- ZonePB.ATPreqPointer = 0L;
- ZonePB.ATPbdsPointer = (Ptr)&myZoneBDS;
- ZonePB.ATPnumOfBuffs = 1;
- ZonePB.ATPtimeOutVal = 3;
- ZonePB.ATPretryCount = 3;
-
- /*
- * make sure to NIL this field out so bottom three bytes are 0
- */
- ZonePB.ATPuserData = 0x07000000; /* GetLocalZone = 7 */
-
- if(PSendRequest(&ZonePB, false) != noErr)
- myZoneBuffer[0] = 0;
- }
-
-
- void doGetZoneListPrePh2()
- {
- BDSElement myZoneBDS;
- ATPParamBlock ZonePB;
- OSErr theResult;
- long tempUserData;
- Ptr theBufferPtr;
- short zIndex, zoneCallType;
- short NumZonesGot = 0, totalZones = 0;
- Boolean DontGetMoreZones;
- extern ListHandle zonesList;
- Ptr returnBuffer;
-
- zIndex = 1;
- zoneCallType = _GetZoneList;
- DontGetMoreZones = false;
-
- returnBuffer = NewPtr(33*300); /* size of maxstring size * 300 zones */
-
- theBufferPtr = NewPtr(578); /* size of BDS */
- if(MemError()==noErr) {
- while(!DontGetMoreZones) {
- zIndex += NumZonesGot; /* index count. 1 for start */
- myZoneBDS.buffSize = 578;
- myZoneBDS.buffPtr = theBufferPtr;
- myZoneBDS.dataSize = 0;
- myZoneBDS.userBytes = 0;
-
- ZonePB.ATPatpFlags = 0;
- ZonePB.ATPioCompletion = 0L;
- ZonePB.ATPuserData = 0; /* ATP user data */
- ZonePB.ATPaddrBlock = gTheBridgeAddress;
- ZonePB.ATPreqLength = 0;
- ZonePB.ATPreqPointer = 0L;
- ZonePB.ATPbdsPointer = (Ptr)&myZoneBDS;
- ZonePB.ATPnumOfBuffs = 1;
- ZonePB.ATPtimeOutVal = 4;
- ZonePB.ATPretryCount = 4;
-
- BlockMove((Ptr) &zoneCallType + 1, (Ptr) &tempUserData, 1L);
- BlockMove((Ptr) &zIndex, (Ptr)&tempUserData + 2, 2L);
-
- ZonePB.ATPuserData = tempUserData;
-
- theResult = PSendRequest(&ZonePB, false);
-
- if(theResult == noErr) {
- tempUserData = myZoneBDS.userBytes;
- BlockMove((Ptr) &tempUserData, (Ptr) &DontGetMoreZones, 1); /* the highbyte will be nonzero if its the last packet of zones */
- BlockMove((Ptr)&tempUserData + 2, (Ptr) &NumZonesGot, 2);
-
- addToUnpackedBuffer(myZoneBDS.buffPtr, returnBuffer, NumZonesGot, totalZones);
-
- totalZones += NumZonesGot;
- }
- }
-
- SetZoneCells(returnBuffer, totalZones);
-
- DisposPtr(theBufferPtr);
- DisposPtr(returnBuffer);
- }
-
- }
-
- Boolean zonesPresent()
- {
- short theBridgeNode = 0;
- short theBridgeNet = 0;
- short node;
- OSErr err;
-
- err = GetNodeAddress(&node, &theBridgeNet);
- /*
- * On an extended network, this node ID is simply a flag. Use _GetAppletalkInfo to get the
- * real 24 bit address of the last router heard from.
- */
- theBridgeNode = GetBridgeAddress();
-
- if (theBridgeNet != 0 && theBridgeNode != 0) {
- gTheBridgeAddress.aNet = theBridgeNet;
- gTheBridgeAddress.aNode = theBridgeNode;
- gTheBridgeAddress.aSocket = kBridgeSocket;
- return true;
- }
- else
- return false;
- }
-
-
- void setItemString(DialogPtr whichDialog, short whichItem, Str255 str)
- {
- Rect r;
- short kind;
- Handle h;
-
- GetDItem(whichDialog, whichItem, &kind, &h, &r);
- SetIText(h, str);
- }
-
-
- void getTheZoneList()
- {
- if (zonesPresent()) {
-
- /*
- * if AppleTalk Phase 2 is present (>= v53) then use new call
- */
- if(gHasPhase2)
- doGetZoneListPhs2();
- else
- doGetZoneListPrePh2();
- }
- else {
- /*
- * no zones. inform user of this.
- */
- tellUserNoZones();
- }
- }
-
-
- void processListUpdate()
- {
- Str255 tempStr, errorStr;
-
- if(gPBLkUP->myMPP.MPPioResult >= noErr) {
- NumToString((long) gPBLkUP->myMPP.NBPnumGotten, tempStr);
- Pstrcat((char *) &tempStr, (char *) "\p items");
-
- SetObjectTypeCells(gBuffPtr, gPBLkUP->myMPP.NBPnumGotten);
- }
- else {
- NumToString((long) gPBLkUP->myMPP.MPPioResult, errorStr);
- tempStr[0] = 0;
- Pstrcat( (char *) &tempStr, (char *) "\pError ID = ");
- Pstrcat((char *) &tempStr, (char *) &errorStr);
- }
-
- gUpdateListFlag = false;
- gLookupFinished = true;
-
- /* nil out text since we're done looking */
- ParamText("\p", "\p", "\p", "\p");
-
- setItemString(gMyDialog, (short) kObjectCountID, tempStr);
-
- invalidateItem(kProgressID);
- invalidateItem(kObjectCountID);
- }
-
-
- void myCompletionRoutine()
- {
- saveThatA5();
-
- gUpdateListFlag = true;
-
- restoreThatA5();
- }
-
- char giveMeItemValue(short whichItem)
- {
- Rect r;
- short kind;
- Handle h;
- Str255 str;
- long value;
-
- GetDItem(gLookupDialog, whichItem, &kind, &h, &r);
- GetIText(h, str);
- StringToNum(str, &value);
-
- if(value>255) {
- value = 255L;
- SetIText(h, "\p255");
- }
- else if(value<0) {
- value = 0L;
- SetIText(h, "\p0");
- }
- return (short)value;
- }
-
- void giveMeItemString(short whichItem, Str255 str)
- {
- Rect r;
- short kind;
- Handle h;
-
- GetDItem(gLookupDialog, whichItem, &kind, &h, &r);
- GetIText(h, str);
- }
-
- void getTypesNamesInZone(char * NBPZone)
- {
- OSErr resultCode;
- Str255 NBPObject, NBPType;
- Str255 tempText;
- Str32 noZoneName = "\pNo zones <*>.";
- Str32 localZone = "\pthe local zone";
- Boolean localFlag = false;
-
- /*myVBLSpinInstall();*/
-
- /*
- * Check whether there are no zones in the zone list
- */
- if (PStrComp((char *)noZoneName, gNameGlob)) {
- gNameGlob[0] = 1;
- gNameGlob[1] = '=';
- localFlag = true;
- }
-
- BlockMove(NBPZone, &gNameGlob[0], 33L);
-
- /*
- * oh dang... there may be an NBPLookup already pending. Kill It first.
- */
- killLookups();
-
- giveMeItemString(kObjectItem, NBPObject);
- giveMeItemString(kTypeItem, NBPType);
- NBPSetEntity((Ptr)&gLookupNTE.nt.entityData[0], (Ptr)NBPObject, (Ptr)NBPType, (Ptr)NBPZone);
-
- gPBLkUP->myA5 = *(long *)(CurrentA5); /* get the Current A5 */
-
- gLookupFinished = false;
-
- gPBLkUP->myMPP.MPPioCompletion = (ProcPtr) myCompletionRoutine;
- gPBLkUP->myMPP.NBPinterval = giveMeItemValue(kIntervalItem);
- gPBLkUP->myMPP.NBPcount = giveMeItemValue(kCountItem);
- gPBLkUP->myMPP.NBPentityPtr = (Ptr)&gLookupNTE.nt.entityData;
- gPBLkUP->myMPP.NBPretBuffSize = 30000L;
- gPBLkUP->myMPP.NBPretBuffPtr = (Ptr) gBuffPtr;
- gPBLkUP->myMPP.NBPmaxToGet = 300; /* should be plenty */
-
- resultCode = PLookupName((MPPParamBlock *) &gPBLkUP->myMPP, true);
-
- /*
- * inform the user of what we are doing
- * and zero out current entity count.
- */
- tempText[0] = 0;
- if (localFlag)
- Pstrcat((char *) &tempText, (char *) localZone);
- else
- Pstrcat((char *) &tempText, (char *) NBPZone);
-
- Pstrcat((char *) &tempText, (char *) "\p…");
- ParamText("\p", "\p", "\plooking in:", tempText);
-
- tempText[0] = 0;
- setItemString(gMyDialog, (short) kObjectCountID, tempText);
-
- invalidateItem(kProgressID);
- invalidateItem(kObjectCountID);
- }
-
-
- /*
- * GetMyZone function
- */
- void doGetMyZonePhs2()
- {
- XCallParam xpb;
- OSErr resultCode;
- char myZoneNameBuffer[33];
- short refNum;
-
- resultCode = OpenDriver("\p.XPP", &refNum);
-
- xpb.ioRefNum = refNum;
- xpb.csCode = xCall;
- xpb.xppSubCode = zipGetMyZone;
- xpb.zipBuffPtr = (Ptr) &myZoneNameBuffer;
- xpb.zipInfoField[0] = 0; /* ALWAYS 0 */
- resultCode = PBControl((ParmBlkPtr) &xpb, false);
- }
-
- void doGetLocalZonesPhs2()
- {
- XCallParam xpb;
- OSErr resultCode = 0;
- Ptr returnBuffer, theBufferPtr;
- short refNum;
- short totalZones = 0;
-
- resultCode = OpenDriver("\p.XPP", &refNum);
-
- returnBuffer = NewPtr(33L*300L); /* size of maxstring size * 300 zones */
-
- theBufferPtr = NewPtr(578); /* size of BDS */
- if(MemError()==noErr) {
-
- xpb.zipInfoField[0] = 0; /* ALWAYS 0 on first call. has state info on subsequent calls */
- xpb.zipLastFlag = 0;
-
- xpb.ioRefNum = refNum;
- xpb.csCode = xCall;
- xpb.xppSubCode = zipGetLocalZones;
- xpb.xppTimeout = 3;
- xpb.xppRetry = 4;
- xpb.zipBuffPtr = (Ptr) theBufferPtr;
-
- while(xpb.zipLastFlag == 0 && resultCode == 0) {
-
- resultCode = PBControl((ParmBlkPtr) &xpb, false);
-
- if(resultCode == noErr) {
- addToUnpackedBuffer(theBufferPtr, returnBuffer, xpb.zipNumZones, totalZones);
- totalZones += xpb.zipNumZones;
- }
- }
-
- if(resultCode == noErr)
- SetZoneCells(returnBuffer, totalZones);
-
- DisposPtr(theBufferPtr);
- DisposPtr(returnBuffer);
- }
- }
-
- /*
- * When AppleTalk Phase 2 is present, things go a bit easier.
- */
- void doGetZoneListPhs2()
- {
- XCallParam xpb;
- OSErr resultCode = 0;
- Ptr returnBuffer, theBufferPtr;
- short refNum;
- short totalZones = 0;
-
- resultCode = OpenDriver("\p.XPP", &refNum);
-
- returnBuffer = NewPtr(33*300); /* size of maxstring size * 300 zones */
-
- theBufferPtr = NewPtr(578); /* size of BDS */
-
- if(MemError()==noErr) {
- xpb.zipInfoField[0] = 0; /* ALWAYS 0 on first call. has state info on subsequent calls */
- xpb.zipInfoField[1] = 0; /* ALWAYS 0 on first call. has state info on subsequent calls */
- xpb.zipLastFlag = 0;
-
- xpb.ioRefNum = refNum;
- xpb.csCode = xCall;
- xpb.xppSubCode = zipGetZoneList;
- xpb.xppTimeout = 3;
- xpb.xppRetry = 4;
- xpb.zipBuffPtr = (Ptr) theBufferPtr;
-
- while(xpb.zipLastFlag == 0 && resultCode == 0) {
- resultCode = PBControl((ParmBlkPtr) &xpb, false);
-
- if(resultCode == noErr) {
- addToUnpackedBuffer(theBufferPtr, returnBuffer, xpb.zipNumZones, totalZones);
- totalZones += xpb.zipNumZones;
- }
- }
- /*
- * If all went well, add zone names to our list.
- */
- if(resultCode == noErr)
- SetZoneCells(returnBuffer, totalZones);
-
- /*
- * Dispose of memory we allocated.
- */
- DisposPtr(theBufferPtr);
- DisposPtr(returnBuffer);
- }
- }
-
-
-
- #define kEchoType 4
-
- void setupEchoDialog(DialogPtr echoDialog, myNetworkEntity *myEnt)
- {
- short kind;
- Handle h;
- Rect r;
- Str32 noZoneName = "\pNo zones <*>.";
- Str32 localZone = "\plocal zone";
- Boolean localFlag = false;
-
- extern pascal void aboutDialogOKFrame();
-
- GetDItem(echoDialog, 10, &kind, &h, &r);
- SetIText(h, myEnt->object);
-
- GetDItem(echoDialog, 11, &kind, &h, &r);
- SetIText(h, myEnt->type);
-
- GetDItem(echoDialog, 12, &kind, &h, &r);
- if (PStrComp((char *)noZoneName, gNameGlob))
- SetIText(h, localZone);
- else
- SetIText(h, gNameGlob);
-
- /*
- * set up the userItem proc for the "OK" button outline
- */
- GetDItem(echoDialog, 13, &kind, &h, &r);
- SetDItem(echoDialog, 13, userItem, (Handle) aboutDialogOKFrame, &r);
- }
-
-
- void doEcho(myNetworkEntity *myEnt)
- {
- MPPParamBlock myMPP;
- OSErr err;
- Boolean gotEcho = false;
- WDSElement myWDS[3]; /* minimum of 3 WDS elements in a Write Data Structure */
- Ptr gHdrPtr;
- Ptr myBuffer;
- long myTicks, myWaitTicks, startTicks, stopTicks;
- unsigned char myHops;
- DialogPtr echoDialog;
- Str255 str;
- short kind;
- Handle h;
- Rect r;
- short itemHit;
- AddrBlock destAddress;
- long tempL;
- GrafPtr savedPort;
- QHdr freeQ, usedQ;
- PacketBuffer buffers[kNumBuffers];
- PacketPtr bufPtr;
- short i;
-
- GetPort(&savedPort);
-
- MYVBLSPININSTALL();
-
- #ifdef THINK_C
- StringToNum((void *) myEnt->net, (long *) &tempL);
- destAddress.aNet = (short) tempL;
- StringToNum((void *) myEnt->node, (long *) &tempL);
- destAddress.aNode = (short) tempL;
- StringToNum((void *) myEnt->socket, (long *) &tempL);
- #else
- StringToNum((Str255) myEnt->net, (long *) &tempL);
- destAddress.aNet = tempL;
- StringToNum((Str255) myEnt->node, (long *) &tempL);
- destAddress.aNode = tempL;
- StringToNum((Str255) myEnt->socket, (long *) &tempL);
- #endif
- destAddress.aSocket = tempL;
-
- echoDialog = GetNewDialog(131, 0L, (WindowPtr) -1L);
- SetPort(echoDialog);
-
- TextFont(geneva);
- TextSize(9);
-
- setupEchoDialog(echoDialog, myEnt);
-
- /* set up the free and used queues */
- freeQ.qFlags = 0;
- freeQ.qHead = nil;
- freeQ.qTail = nil;
-
- usedQ.qFlags = 0;
- usedQ.qHead = nil;
- usedQ.qTail = nil;
-
- for (i=0; i<kNumBuffers; i++, freeQ.qFlags ++)
- Enqueue((QElemPtr)&buffers[i], &freeQ);
-
- err = SL_INITSKTLISTENER(&freeQ, &usedQ);
- if (err == noErr) {
-
- myMPP.DDPlistener = (Ptr) SL_THELISTENER;
-
- myMPP.DDPsocket = 0;
- err = POpenSkt(&myMPP, false);
-
- gHdrPtr = NewPtr(17); /* max header size */
-
- destAddress.aSocket = 4; /* Echoer socket */
- myBuffer = NewPtr(ddpMaxData);
- *myBuffer = 1; /* tell their Echoer we want a reply with a 1 in the first byte */
-
- BuildDDPwds((Ptr) &myWDS, gHdrPtr, myBuffer, destAddress, kEchoType, ddpMaxData);
-
- myMPP.DDPchecksumFlag = true;
- myMPP.DDPwdsPointer = (Ptr) &myWDS;
-
- startTicks = TickCount(); /* start the timer! */
-
- err = PWriteDDP(&myMPP, false);
-
- myWaitTicks = TickCount() + 600L; /* wait 10 seconds for reply */
-
- while(myWaitTicks > TickCount() && !usedQ.qHead) {}
-
- if(usedQ.qHead) {
- bufPtr = (PacketPtr)usedQ.qHead; /* get the packet ptr */
- /* we could check the DDP type in the buffer_type field
- * but we leave it as an exercise to the reader.
- * Note that the way the usedQ is structured so that
- * we could check whether the packet is for us, or for
- * some other process which utilizes the same listener.
- * In the next step we dequeue the packet so that it
- * doesn't get overwritten */
- if (Dequeue((QElemPtr)usedQ.qHead, &usedQ) == noErr) {
- stopTicks = bufPtr->buffer_Ticks;
- myTicks = stopTicks - startTicks;
-
- GetDItem(echoDialog, 4, &kind, &h, &r);
- myHops = bufPtr->buffer_Hops;
- NumToString((long) myHops, (void *) &str);
- SetIText(h, str);
-
- GetDItem(echoDialog, 5, &kind, &h, &r);
- NumToString(myTicks, (void *) &str);
- SetIText(h, str);
- /* requeue the packet buffer for use. */
- Enqueue((QElemPtr)bufPtr, &freeQ);
- }
- else {
- GetDItem(echoDialog, 6, &kind, &h, &r);
- SetIText(h, "\pWah… packet Dequeue error occured");
- }
- }
- else {
- GetDItem(echoDialog, 6, &kind, &h, &r);
- SetIText(h, "\pWah… no echo reply received!");
- }
- DisposPtr(gHdrPtr);
- DisposPtr(myBuffer);
- err = PCloseSkt(&myMPP, false);
- }
- else {
- GetDItem(echoDialog, 6, &kind, &h, &r);
- SetIText(h, "\pWah… can't initalize socket listener");
- }
-
- centerDialog((WindowPtr) echoDialog);
-
- STOPANDREMOVESPINNINGCURSOR();
-
- InitCursor();
- ShowWindow(echoDialog);
-
- ModalDialog(0L, &itemHit);
- DisposDialog(echoDialog);
-
- SetPort(savedPort);
- }
-
- /*
- * Here's our AppleTalk Transition Queue handler - we just want
- * to know if the user shuts down AppleTalk, or changes connections
- * and do the right thing like deregister our NBP name.
- */
-
- long ATalkTransQueue(long selector, myATQEntry *q, void *p)
- {
- long returnVal = 0; /* return 0 for unrecognized events */
- NameChangePtr myNameChangePtr;
- TNewCRTransPtr myTNewCRTransPtr;
- TNetworkTransitionPtr myTNetworkTransitionPtr;
- NetworkTransitionProcPtr myNTProcPtr;
- StringPtr newNamePtr;
- long checkThisNet;
- char **t;
- short myCableLo, myCableHi;
-
-
- /*
- * This is the dispatch part of the routine. We'll check the selector passed into
- * the task; its location is 4 bytes off the stack (selector).
- */
-
- switch(selector) {
- case ATTransOpen:
- /*
- * Someone has opened the .MPP driver. Let's initialize ourselves
- */
-
- InitAppleTalkVars();
- break;
-
- case ATTransClose:
- /*
- * .MPP is going to shut down no matter what we do. Call Cleanup routine
- */
- closeUpOurAppleTalk();
- break;
-
-
- case ATTransNameChangeTellTask:
- /*
- * Someone is changing the Flagship name and there is nothing we can do.
- * The parameter 'p' is a pointer to a Pascal-style string that holds the new
- * Flagship name.
- */
- newNamePtr = (StringPtr) p;
-
- /*
- * You should deregister any previously registered NBP entries under the
- * 'old' Flagship name. Always return 0.
- */
- break;
-
- case ATTransNameChangeAskTask:
- /*
- * Someone is messing with the Flagship name.
- * With this event, the parameter 'p' actually means something. 'p' is
- * a pointer to a NameChangeInfo record. The newObjStr field contains the
- * new Flagship name. Try to register a new entity using the new Flagship name.
- * Returning a value of 0 means it's OK to change the Flagship name.
- */
- myNameChangePtr = (NameChangePtr)p;
-
- /*
- * If the NBPRegister is unsuccessful, return the error. You must also set
- * p->name pointer with a pointer to a Pascal-style string of the process
- * name.
- */
- break;
-
- case ATTransCancelNameChange:
- /*
- * Just kidding, we didn't really want to change that name after
- * all. Remove new NBP entry registered under the ATTransNameChangeAskTask
- * Transition. In our case, we'll just fall through. 'p' will be nil. Remember
- * to return 0.
- */
- break;
-
- case ATTransCableChange:
- /*
- * The cable range for the network has changed. The pointer 'p' points
- * to a structure with the new network range. (TNewCRTransPtr)p->newCableLo
- * is the lowest value of the new network range. (TNewCRTransPtr)p->newCableHi
- * is the highest value of the new network range. After handling this event,
- * always return 0.
- */
- myTNewCRTransPtr = (TNewCRTransPtr)p;
- myCableLo = myTNewCRTransPtr->newCableLo;
- myCableHi = myTNewCRTransPtr->newCableHi;
- break;
-
- } /* end of switch */
-
- /*
- * return value in register D0
- */
- return returnVal;
- }
-
-
- /*
- * This routine doesn't do anything, but was thrown in at not extra cost to you
- * the user.
- */
-
- /*
- void doGetAppleTalkInfo()
- {
- getAppleTalkInfoParam gpb;
- OSErr resultCode;
- short refNum;
- char myZoneNameBuffer[33];
-
- Debugger();
- resultCode = OpenDriver("\p.MPP", &refNum);
-
- gpb.ioRefNum = refNum;
- gpb.csCode = getAppleTalkInfo;
- gpb.version = 1;
- gpb.LALength = 0L;
- gpb.linkAddr = 0L;
- gpb.zoneName = (Ptr) &myZoneNameBuffer;
-
- resultCode = PBControl(&gpb, false);
- }
- */
-
- /*
- typedef struct
- {
- char cmdByte;
- char fpData;
- char fpExtra[86];
- } AFPLoginRec;
-
- typedef struct
- {
- char cmdByte;
- char bitMap;
- char volName[27];
- char password[8];
- } cbOpenVolRec;
-
- typedef struct
- {
- long srvTime;
- char volCount;
- char volArray;
- char volExtra[64];
- } ServerRec;
-
-
- pascal void ack()
- {
- SysBeep(2);
- }
- extractAndKill()
- {
- ATPParamBlock killerPB;
- BDSElement killerBDS;
- OSErr resultCode;
-
- XPPParmBlkPtr xppAccess;
- XPPParamBlock *xppGtSrvPrms;
- AFPLoginRec theCB, theCBGtSrvPrms;
- ServerRec *theServerRec;
- cbOpenVolRec cbOpenVol;
- char *vers, *auth, *myName, *myPWord;
- short index;
- char theRB[578];
- Ptr a;
- short gXPPRef, rbSize;
- AddrBlock serverAddress;
- char entityData[99];
- Ptr gSCBPtr;
-
- serverAddress.aNet = 14022;
- serverAddress.aNode = 41;
- serverAddress.aSocket = 252;
-
- resultCode = OpenXPP(&gXPPRef);
- xppAccess = (XPPParmBlkPtr)NewPtr(sizeof(XPPParamBlock));
- xppGtSrvPrms = (XPPParmBlkPtr)NewPtr(sizeof(XPPParamBlock));
- theServerRec = (ServerRec *)NewPtr(sizeof(ServerRec)*20);
-
- gSCBPtr = NewPtr(scbMemSize);
-
- theCB.cmdByte = afpLogin;
-
- a = &theCB.fpData;
-
- index = 0L;
- vers = "\pAFPVersion 1.1";
- BlockMove((Ptr)vers, (Ptr)a, vers[0]+1L);
- index = vers[0]+1L;
-
- auth = "\pNo User Authent";
- BlockMove((Ptr)auth, (Ptr)a+index, (long)auth[0]+1L);
- index += auth[0]+1L;
-
- rbSize = 578;
-
- xppAccess->cmdResult = 0;
- xppAccess->ioRefNum = xppRefNum; /*its always -41 /
- xppAccess->XPPaspTimeout = 3;
- xppAccess->XPPaspRetry = 3;
- xppAccess->XPPcbSize = (short)2 + index;
- xppAccess->XPPcbPtr = (Ptr)&theCB;
- xppAccess->XPPrbSize = rbSize;
- xppAccess->XPPrbPtr = (Ptr)&theRB; /*this is where server info will be place /
- xppAccess->XPPafpAddrBlock = serverAddress;
- xppAccess->XPPafpSCBPtr = gSCBPtr; /* this is where server info will be place /
- xppAccess->XPPafpAttnRoutine = (Ptr)ack;
-
- resultCode = AFPCommand(xppAccess, false);
-
- if(xppAccess->cmdResult == noErr ) {
- theCBGtSrvPrms.cmdByte = afpGetSParms;
- rbSize = sizeof(ServerRec)*20;
-
- xppGtSrvPrms->cmdResult = 0;
- xppGtSrvPrms->ioRefNum = xppRefNum;
- xppGtSrvPrms->XPPsessRefnum = xppAccess->XPPsessRefnum;
- xppGtSrvPrms->XPPaspTimeout = 5;
- xppGtSrvPrms->XPPcbSize = 2;
- xppGtSrvPrms->XPPcbPtr = (Ptr)&theCBGtSrvPrms;
-
- xppGtSrvPrms->XPPrbSize = rbSize;
- xppGtSrvPrms->XPPrbPtr = (Ptr)theServerRec; /*this is where server info will be place /
-
- resultCode = AFPCommand(xppGtSrvPrms, false);
-
- cbOpenVol.cmdByte = afpOpenVol;
- cbOpenVol.bitMap = 511;
- BlockMove(theServerRec->volExtra, &cbOpenVol.volName[0], 27L);
-
- rbSize = sizeof(ServerRec)*20;
-
- xppGtSrvPrms->cmdResult = 0;
- xppGtSrvPrms->ioRefNum = xppRefNum;
- xppGtSrvPrms->XPPsessRefnum = xppAccess->XPPsessRefnum;
- xppGtSrvPrms->XPPaspTimeout = 5;
- xppGtSrvPrms->XPPcbSize = sizeof(cbOpenVolRec);
- xppGtSrvPrms->XPPcbPtr = (Ptr)&cbOpenVol;
-
- xppGtSrvPrms->XPPrbSize = 30;
- xppGtSrvPrms->XPPrbPtr = (Ptr)theRB; /*this is where server info will be place /
-
- resultCode = AFPCommand(xppGtSrvPrms, false);
-
-
- theCBGtSrvPrms.cmdByte = afpLogout;
- rbSize = sizeof(ServerRec)*20;
-
- xppGtSrvPrms->cmdResult = 0;
- xppGtSrvPrms->ioRefNum = xppRefNum;
- xppGtSrvPrms->XPPsessRefnum = xppAccess->XPPsessRefnum;
- xppGtSrvPrms->XPPaspTimeout = 5;
- xppGtSrvPrms->XPPcbSize = 2;
- xppGtSrvPrms->XPPcbPtr = (Ptr)&theCBGtSrvPrms;
-
- xppGtSrvPrms->XPPrbSize = rbSize;
- xppGtSrvPrms->XPPrbPtr = (Ptr)theServerRec;
-
- resultCode = AFPCommand(xppGtSrvPrms, false);
- }
- }
-
- */